﻿using Entity;
using IntelligentPharmacy.Entity;
using IntelligentPharmacy.publicclass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentPharmacy.httprequest
{
    class requestDao
    {
        ConsumablesCabinet.ServiceReference1.CommonClient requestCs = new ConsumablesCabinet.ServiceReference1.CommonClient();

        public requestDao()
        {
             //requestCs = new ServiceReference3.CommonClient("", "");
            // this.requestCs = new ServiceReference3.CommonClient();
        
        }
        /// <summary>
        /// 注册设置
        /// </summary>
        /// <param name="infor"></param>
        /// <returns></returns>
        public information<SpdId> InsertDeviceInfo(List<DeviceEntity> infor)
        {
            information<SpdId> test = new information<SpdId>();
            try
            {
                Logger.WriteLog("注册成功------------");
                baseList<DeviceEntity> baselist = new baseList<DeviceEntity>();
                baselist.list = infor;
                string json = JsonToObject.Serialize(baselist);
                string rjson = requestCs.getMacRel(json);
                test = JsonToObject.Deserialize<information<SpdId>>(rjson);
            }
            catch(Exception e)
            {

            }
            return test;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public information<UserFace> register(UserEntity info)
        {
            information<UserFace> test = new information<UserFace>();
            try
            {
                Logger.WriteLog("登录成功------------");
                string json = JsonToObject.Serialize(info);
                string jsonr = requestCs.getEmpInfo(json);
                test = JsonToObject.Deserialize<information<UserFace>>(jsonr);
            }
            catch(Exception e)
            {

            }
            return test;
        }
        /// <summary>
        /// 获取设备信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string getDeviceIdAndName(information<DeviceEntity> info)
        {
            information<DeviceEntity> infors = new information<DeviceEntity>();
            string json = JsonToObject.Serialize(info);

            throw new NotImplementedException();
        }
        /// <summary>
        /// 出入库记录
        /// </summary>
        /// <param name="lists"></param>
        public bool outPutCabinet(baseList<OutPutEntity> lists)
        {
            information<Object> info;
            try
            {
                Logger.WriteLog("登录成功------------");
                string json = JsonToObject.Serialize(lists);
                string jsons = requestCs.getInoutInfo(json);
                info=JsonToObject.Deserialize<information<Object>>(jsons);
            }catch(Exception e) {
                return false;
            }
            return info.success;
        }
        /// <summary>
        /// 根据标签id获取耗材信息
        /// </summary>
        /// <param name="lists"></param>
        public information<MaterialnformationEntity> getInoutInfo(baseList<TagEntity> lists)
        {
            information<MaterialnformationEntity> test = new information<MaterialnformationEntity>();
            try
            {
                string json = JsonToObject.Serialize(lists);
                string jsons = requestCs.getRfInfo(json);
                test = JsonToObject.Deserialize<information<MaterialnformationEntity>>(jsons);
            }
            catch(Exception e) { }
      
            return test;
        }
        /// <summary>
        /// 获取库存
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public information<TagEntity> getStorckList(Dictionary<string,string> obj)
        {
            string json=JsonToObject.Serialize(obj);
            string JsonStorckList = requestCs.getStoreQty(json);
            information<TagEntity> tagEntities = JsonToObject.Deserialize<information<TagEntity>>(JsonStorckList);
            return tagEntities;
        }
        /// <summary>
        /// 获取出入库记录
        /// </summary>
        /// <returns></returns>
        public information<MaterialnformationEntity> getOutPutRecord(Querydto querydto)
        {
            string json = JsonToObject.Serialize(querydto);
            string JsonStorckList = requestCs.getInoutRecord(json);
            information<MaterialnformationEntity> detailsList =JsonToObject.Deserialize<information<MaterialnformationEntity>>(JsonStorckList);
            return detailsList;
        }
    }
}
